package com.wbu.service;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.wbu.entity.Admin;
import com.wbu.mapper.AdminMapper;
@Service
public class AdminService {
	
	@Autowired
	private AdminMapper adminMapper;
	
	public Admin login(Admin admin) {
		List<Admin> adminList = adminMapper.login(admin);
		return adminList.size() > 0 ?adminList.get(0):null;
	}
	
	public Admin findById(int id) {
		return adminMapper.findById(id);
	}
	
	public List<Admin> findAll() {
		return adminMapper.findAll();
	}
	
	public List<Admin> findByName(String name) {
		return adminMapper.findByName(name);
	}
	
	public boolean addAdmin(Admin admin) {
		int result = adminMapper.insert(admin);
		return (result > 0)?true:false;
	}
	
	public boolean updateAdmin(Admin admin) {
		int result = adminMapper.update(admin);
		return (result > 0)?true:false;
	}
	
	public boolean deleteAdmin(int id) {
		int result = adminMapper.delete(id);
		return (result > 0)?true:false;
	}
	
}
